#pragma once

#include<vector>

namespace cyq
{
	template<size_t N>
	class bitset
	{
	public:
		bitset()
		{
			_a.resize(N / 32 + 1);
		}

		void set(size_t x)
		{
			int i = x / 32;
			int j = x % 32;
			_a[i] |= (1 << j);
		}

		void reset(size_t x)
		{
			int i = x / 32;
			int j = x % 32;
			_a[i] &= (~(1 << j));
		}

		bool test(size_t x)
		{
			int i = x / 32;
			int j = x % 32;
			return _a[i] & (1 << j);
		}
	private:
		vector<int> _a;
	};

	template<size_t N>
	class twobitset
	{
	public:
		void set(size_t x)
		{
			if (!bs1.test(x) && !bs2.test(x))
			{
				bs2.set(x);
			}
			else if (!bs1.test(x) && bs2.test(x))
			{
				bs1.set(x);
				bs2.reset(x);
			}
		}


		bool is_once(size_t x)
		{
			return !bs1.test(x)&&bs2.test(x);
		}
	private:
		bitset<N> bs1;
		bitset<N> bs2;
	};
}
